﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi
{
    public partial class mfVehicleInfo : msBsc.Cls.mbPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override void DoAction()
        {
            if (strAction == "init")
            {
                SetVehicleInfo();
                base.DoAction();
            }
            else if (strAction == "GetVehicleEvlution")
            {
                SetEvlutionInfo();
            }
            else if (strAction=="telClick")
            {
                base.DoAction();
            }
        }

        private void SetVehicleInfo()
        {
            string vehicleId = this.GetParamHtValue("vehicleId");

            if (string.IsNullOrEmpty(vehicleId))
            {
                this.ExecJScript("alert('车辆信息有误，请检查')");
            }

            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo objCBizVehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                System.Data.DataSet ds = objCBizVehicleInfo.SelectByIds(string.Empty, vehicleId);

                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    this.ExecJScript("alert('该车辆不存在，请检查')");
                }

                string serviceType = Enum.GetName(typeof(msBsc.AppLogic.DataAlc.cls.CommonEnum.ServiceTypeEnum), ds.Tables[0].Rows[0]["VEHICLE_SERVICE_TYPE"]);

                string execJsJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", 200, "");

                this.ExecJScript("SetVehicleInfo(" + execJsJson + ");$('#spaServiceType').text('" + serviceType + "');");
            }
        }

        private void SetEvlutionInfo()
        {
            string vehicleId = this.GetParamHtValue("vehicleId");
            
            if (string.IsNullOrEmpty(vehicleId))
            {
                return;
            }

            using (msBsc.AppLogic.DataAlc.CBizCustomerEvlution objCBizCustomerEvlution = new AppLogic.DataAlc.CBizCustomerEvlution())
            {

                Epm.AppLogic.Framework.CDbParmCollection parmCollection = new Epm.AppLogic.Framework.CDbParmCollection();

                parmCollection.Add(new Epm.AppLogic.Framework.CDbParm("vehicleId", System.Data.ParameterDirection.Input, Epm.AppLogic.Framework.EDbType.String, 36, vehicleId));

                System.Data.DataSet ds = objCBizCustomerEvlution.DataObj.QueryBySQL(@"
SELECT
T1.*
,C.CUSTOMER_NICK
,C.CUSTOMER_DEFAULT_PIC
FROM (SELECT
T.*
,B.EVLUTION_IMAGES_SOURCE
FROM (SELECT
A.CUSTOMER_EVLUTION_ID
,A.EVLUTION_CUSTOMER_ID
,A.EVLUTION_CONTENT
,A.EVLUTION_TIME
FROM DJK_CUSTOMER_EVLUTION A
WHERE A.EVLUTION_VEHICLE_ID=@vehicleId) T 
LEFT JOIN DJK_EVLUTION_IMAGES B ON T.CUSTOMER_EVLUTION_ID=B.EVLUTION_ID) T1
LEFT JOIN DJK_CUSTOMER_REGISTER C ON T1.EVLUTION_CUSTOMER_ID=C.CUSTOMER_REGISTER_ID", parmCollection);

                string execJsJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "CUSTOMER_EVLUTION_ID,CUSTOMER_NICK,CUSTOMER_DEFAULT_PIC,EVLUTION_CUSTOMER_ID,EVLUTION_CONTENT,EVLUTION_TIME", 1, 200, "");

                this.ExecJScript(@"var _html = $('#set_evlution_list').html();
                            laytpl(_html).render(" + execJsJson + @", function (render) {
                                $('#evlution-list').html(render);
                            })");
            }
        }
    }
}